
Overlord.Inherits(Creature);
function Overlord(name) {
  this.Inherits(Creature, name);
  this.img = resource.overlord;
  this.summons = [];
  this.addAction(new Action('End turn', resource.selected));
  this.addSummons(new Action('Summon Goblin', resource.selected));
  this.addSummons(new Action('Summon Bat', resource.selected));
  this.addSummons(new Action('Summon Unicorn', resource.selected));
}

/**
 * Adds a Summons Action to this Overlord.
 *
 */
Overlord.prototype.addSummons = function(action) {
  this.summons[this.summons.length] = action;
}


/**
 * Removes a Summons Action from this Overlord.
 *
 */
Overlord.prototype.removeSummons = function(action) {
  for (var i = 0; i < this.summons.length; i++)
    if (this.summons[i] == action)
      this.summons.remove(i, i);
}


/**
 * Removes all Summons Actions from this Overlord.
 *
 */
Overlord.prototype.clearSummons = function() {
  this.summons = [];
}

/**
 * @see Object.moveto
 *
 */
Overlord.prototype.moveto = function(cell) {
  Object.prototype.moveto.call(this, cell);
  this.syncObjectActions(cell);
};


/**
 * @see Object.setLocation
 *
 */
Overlord.prototype.setLocation = function(cell) {
  Object.prototype.moveto.call(this, cell);
  this.syncObjectActions(cell);
};


/**
 * Add Actions to Objects in specified Cell
 *
 */
Overlord.prototype.syncObjectActions = function(cell) {
  for (var i = 0; i < cell.objects.length; i++) {
    if (cell.objects[i].name == 'Summonsing Stone') {
      cell.objects[i].clearActions();
      for (var t = 0; t < this.summons.length; t++)
        cell.objects[i].addAction(this.summons[t]);
    }
  }
};

